<template>
	<view class="container">
		<view class="tip">
			<text>请填写银行卡信息</text>
		</view>

		<view class="list">
			<view class="list-item">
				<text>持卡人</text>
				<input type="text" value="" v-model="person" placeholder="请输入" />
			</view>
			<view class="list-item">
				<text>银行</text>
				<input type="text" value="" v-model="bank_name" placeholder="请输入" />
			</view>
			<view class="list-item">
				<text>银行卡号</text>
				<input type="number" value="" v-model="bank_number" placeholder="请输入" />
			</view>
			<view class="list-item">
				<text>开户行</text>
				<input type="text" value="" v-model="bank_address" placeholder="请输入" />
			</view>
		</view>

		<view class="btn">
			<button type="default" @click="submit">确认</button>
		</view>


	</view>
</template>

<script>
	import {
		bankDetail,
		bank
	} from '../../../api/api.js'
	export default {
		data() {
			return {
				person: '',
				bank_name: '',
				bank_number: '',
				bank_address: ''
			}
		},
		onLoad() {
			this.getBankInfo()
		},
		methods: {
			getBankInfo() {
				bankDetail().then(res => {
					console.log(res)
					if (res.data) {
						this.card = true
						this.person = res.data.realname
						this.bank_name = res.data.bank
						this.bank_number = res.data.bank_card
						this.bank_address = res.data.bank_name
					} else {
						this.card = false
					}
				})
			},
			submit() {
				if (!this.person) {
					uni.showToast({
						icon: 'none',
						title: '请输入持卡人信息'
					})
					return
				}
				if (!this.bank_name) {
					uni.showToast({
						icon: 'none',
						title: '请输入银行名称'
					})
					return
				}
				if (!this.bank_number) {
					uni.showToast({
						icon: 'none',
						title: '请输入银行卡号'
					})
					return
				}
				if (!this.bank_address) {
					uni.showToast({
						icon: 'none',
						title: '请输入开户行信息'
					})
					return
				}
				// 绑定银行卡
				bank({
					realname:this.person,
					bank:this.bank_name,
					bank_card: this.bank_number,
					bank_name:this.bank_address
				}).then(res=>{
					if(res.code == 1){
						uni.redirectTo({
							url:'/pages/agent/user/cash'
						})
					}
				})
				
			}
		}
	}
</script>

<style scoped lang="scss">
	.container {
		width: 100%;
		height: 100%;
		background-color: #f6f6f6;
	}

	.tip {
		width: calc(100% - 60upx);
		height: 80upx;
		line-height: 80upx;
		padding: 0 30upx;
		font-size: 28upx;
		color: #666666;
	}

	.list {
		width: calc(100% - 60upx);
		padding: 0 30upx;
		background-color: #FFFFFF;

		.list-item {
			width: 100%;
			height: 80upx;
			line-height: 80upx;
			padding: 10upx 0;
			display: flex;
			justify-content: space-between;
			border-bottom: 1upx solid #ECECEC;

			input {
				height: 100%;
				min-width: 200upx;
				text-align: right;
			}
		}



	}

	.btn {
		width: calc(100% - 60upx);
		margin: 40upx auto;
		height: 90upx;

		button {
			width: 100%;
			height: 100%;
			height: 90upx;
			border-radius: 45upx;
			background-color: #3eb9fe;
			color: #FFFFFF;
		}
	}
</style>
